package com.sskj.jd.service.impl;

import javax.transaction.Transactional;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sskj.core.annotation.ControllerLogExeTime;
import com.sskj.eng.domain.entity.ListJdjlResponse;
import com.sskj.eng.domain.entity.ListResponse;
import com.sskj.jd.domain.JianDuJiLuQueryParam;
import com.sskj.jd.domain.entity.JianDuJiLu;
import com.sskj.jd.repository.JianDuJiLuRepository;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping(value = "/jd/jdjl", method = { RequestMethod.POST, RequestMethod.GET })
@Transactional
public class JianDuJiLuServiceImpl {

	protected final Log logger = LogFactory.getLog(JianDuJiLuServiceImpl.class);

	@Autowired
	JianDuJiLuRepository jianDuJiLuRepository;

	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/page")
	@ControllerLogExeTime(description = "查询监督记录", log = false)
	@ApiOperation(value = "监督记录", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(name = "keyword", value = "关键字", paramType = "form", dataType = "string"),
			@ApiImplicitParam(name = "userid", value = "用户ID", paramType = "form", dataType = "string"),
			@ApiImplicitParam(name = "sort", value = "排序规则", paramType = "form", dataType = "Sort"),
			@ApiImplicitParam(name = "pageNumber", value = "页号", paramType = "form", dataType = "int"),
			@ApiImplicitParam(name = "pageSize", value = "页的大小", paramType = "form", dataType = "int") })
	public Page<JianDuJiLu> queryPage(@ApiIgnore JianDuJiLuQueryParam jianDuJiLuQueryParam, Pageable pageable) {

		if (jianDuJiLuQueryParam.getJllx().equals("zl")) {
			return jianDuJiLuRepository.findZlPage(jianDuJiLuQueryParam, pageable);

		} else {
			return jianDuJiLuRepository.findAqPage(jianDuJiLuQueryParam, pageable);
		}

	}

	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/dd/page")
	@ControllerLogExeTime(description = "查询监督记录", log = false)
	@ApiOperation(value = "监督记录", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(name = "keyword", value = "关键字", paramType = "form", dataType = "string"),
			@ApiImplicitParam(name = "userid", value = "用户ID", paramType = "form", dataType = "string"),
			@ApiImplicitParam(name = "sort", value = "排序规则", paramType = "form", dataType = "Sort"),
			@ApiImplicitParam(name = "pageNumber", value = "页号", paramType = "form", dataType = "int"),
			@ApiImplicitParam(name = "pageSize", value = "页的大小", paramType = "form", dataType = "int") })
	public ListResponse queryDdPage(@ApiIgnore JianDuJiLuQueryParam jianDuJiLuQueryParam, Pageable pageable) {
		ListResponse rep = new ListResponse();

		try {
			if (jianDuJiLuQueryParam.getJllx().equals("zl")) {
				Page<JianDuJiLu> page = jianDuJiLuRepository.findZlPage(jianDuJiLuQueryParam, pageable);
				rep.setContent(new ListJdjlResponse(page.getNumber(), page.getContent()));

			} else {
				Page<JianDuJiLu> page = jianDuJiLuRepository.findAqPage(jianDuJiLuQueryParam, pageable);
				rep.setContent(new ListJdjlResponse(page.getNumber(), page.getContent()));

			}
			rep.setSuccess(true);
		} catch (Exception e) {
			rep.setSuccess(false);
			e.printStackTrace();
		}

		return rep;
	}

}
